package com.atguigu.digest;


import com.sun.org.apache.xerces.internal.impl.dv.util.Base64;

import java.security.MessageDigest;

public class DigestDemo1 {
    public static void main(String[] args) throws  Exception {
        //原文
        String input = "abc";
        //算法
        String algorithm = "MD5";
        //获取数字摘要对象
        MessageDigest messageDigest = MessageDigest.getInstance(algorithm);
        //获取数字摘要对象的字节对象
        byte[] digest = messageDigest.digest(input.getBytes());

        StringBuilder sb = new StringBuilder();
        for (byte b : digest) {
            //转成16进制
            String s = Integer.toHexString(b & 0xff);
            System.out.println("s = " + s);
            if(s.length() == 1){
                s = "0" + s;
            }
            sb.append(s);
        }
        System.out.println(sb.toString());

    }
}
